'''
Created on 2009-11-11

@author: Jialai_Zhu
'''
from multiprocessing import Process, Lock
import threading
def do_time_func():        
    print 'timer_func'
    global lock 
    lock.release()
    global t
    t.run()
def timer_func():
    try:
        do_time_func()
    except:
        pass

    
from multiprocessing import Process, Lock
import multiprocessing

def f(l):
    print 'def f(l):'
    while 1:
        l.acquire()
        print 'hello world'
    print 'end'    

if __name__ == '__main__':
    global lock
    lock = Lock()

#    for num in range(10):
    p=Process(target=f, args=(lock,))
    p.daemon=True
     

#    Process.current_process().daemon=True 
    lock.acquire()
    print '    lock.acquire()'
    p.start()
    global t        #Notice: use global variable!
    t = threading.Timer(5.0, timer_func)    
    t.start()
    try:  
        p.join()
    except:
        print "xxxxxx"
        t.cancel()
        print p.terminate()    
        exit()    
    